package lab02.test24;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test24 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入第一个日期，如yyyy-mm-dd:");
        String day1 = sc.nextLine();

        Scanner sw = new Scanner(System.in);
        System.out.println("请输入第二个日期，如yyyy-mm-dd:");
        String day2 = sw.nextLine();

        long daytime1 = 0;
        long daytime2 = 0;

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");

        try {
            Date dayTime1 =  simpleDateFormat.parse(day1);
            Date dayTime2 = simpleDateFormat.parse(day2);

            Calendar c1 = Calendar.getInstance();//实例化

            c1.setTime(dayTime1);
            daytime1 = c1.getTimeInMillis();//将日期转化为毫秒

            c1.setTime(dayTime2);
            daytime2 = c1.getTimeInMillis();
        } catch (ParseException e) {
            e.printStackTrace();
        }

        long days = (daytime2 - daytime1)/(24*60*60*1000);
        System.out.println("两日期相差"+days+"天");

    }
}
